package com.bookhouse.service.impl;

import java.util.HashSet;
import java.util.Set;

import com.bookhouse.dao.MenuDao;
import com.bookhouse.domain.Menu;
import com.bookhouse.service.MenuService;

public class MenuServiceImpl implements MenuService {

	private MenuDao menuDao;

	public void setMenuDao(MenuDao menuDao) {
		this.menuDao = menuDao;
	}

	@Override
	public Set<Menu> getAllMenu() {
		Set<Menu> sets = new HashSet<Menu>();
		Menu menu = menuDao.get(Menu.class, 0);
		Set<Menu> levels1 = menu.getChildrenMenu();
		for (Menu level1 : levels1) {
			sets.add(level1);
			level1.setSet(new HashSet<Menu>());
			Set<Menu> levels2 = level1.getChildrenMenu();
			for (Menu level2 : levels2) {
				level1.getSet().add(level2);
			}
		}
		return sets;
	}

}
